package entity

import (
	"fmt"

	"shqsoft.cn/pasnj/base"

	"github.com/jinzhu/gorm"
)

//CswhED 额度导入
type CswhED struct {
	ID        int     `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	KHYF      string  `gorm:"column:KHYF"`
	JYDW      string  `gorm:"column:JYDW"`
	OrganID   int     `gorm:"column:OrganID"`
	LJGSED    float64 `gorm:"column:LJGSED"`
	LJLSED    float64 `gorm:"column:LJLSED"`
	BFSYED    float64 `gorm:"column:BFSYED"`
	LJZED     float64 `gorm:"column:LJZED"`
	LJZSYFFED float64 `gorm:"column:LJZSYFFED"`
	BYJJED    float64 `gorm:"column:BYJJED"`
	BYKFPED   float64 `gorm:"column:BYKFPED"`
}

//TableName 额度导入
func (CswhED) TableName() string {
	return "T_JHCW_JXFP_FPED"

}

//CswhEDEF 返回结构体
func CswhEDEF() base.EntityFunc {
	return func() interface{} {
		entity := CswhED{}
		return &entity
	}
}

//CswhEDESF 返回结构体数组
func CswhEDESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CswhED
		return &entities
	}
}

//BeforeSave 保存前的触发器
func (i *CswhED) BeforeSave(tx *gorm.DB) (err error) {
	sqlEx := "select dbo.GetBackDATE()"
	row := tx.Raw(sqlEx).Row()

	var organid int
	sqlEx = "select ID  from T_Organization  where OrganName=?"
	row = tx.Raw(sqlEx, i.JYDW).Row()
	err = row.Scan(&organid)

	if organid == 0 {
		return fmt.Errorf("经营单位:%s在系统中没有找到！", i.JYDW)
	}
	return

}

func init() {
	base.DaoPoolObj.Put("CswhED", base.NewDefaultDao(CswhEDEF(), CswhEDESF(), nil))

}
